﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
using Users.Interfaces;
using Users.Views;
using RAD.Modules.Scripts.Interfaces;
using RAD.Modules.Scripts.Services;
using RAD.Modules.Scripts.Views;

namespace RAD.Modules.Scripts
{
    /// <summary>
    /// Модуль для реализации функиональности программы
    /// </summary>
    public class ScriptsModule : IModule
    {
        private IUnityContainer _container;
        private IRegionManager _regionManager;

        public ScriptsModule(IUnityContainer container, IRegionManager regionManager)
        {
            _container = container;
            _regionManager = regionManager;
        }

        #region IModule Members

        public void Initialize()
        {
            RegisterViewsAndServices();

            // Заполняем регион скриптов
            IScriptsPresenter presenter = _container.Resolve<IScriptsPresenter>();
            _regionManager.Regions["ScriptsRegion"].Add(presenter.View);

            // Заполняем регион консоли
            IConsoleViewPresenter conPresenter = _container.Resolve<IConsoleViewPresenter>();
            _regionManager.Regions["ConsoleRegion"].Add(conPresenter.View);
        }

        private void RegisterViewsAndServices()
        {
            _container.RegisterType<IParamsSelectDialog, ParamsSelectDialog>();
            _container.RegisterType<IScriptService, ScriptService>(new ContainerControlledLifetimeManager());
            _container.RegisterType<IScriptsView, ScriptsView>();
            _container.RegisterType<IScriptsPresenter, UsersPresenter>();
            _container.RegisterType<IConsoleView, ConsoleView>();
            _container.RegisterType<IConsoleViewPresenter, ConsoleViewPresenter>();
            _container.RegisterType<ICreateShareView, CreateShareView>();
            _container.RegisterType<ICreateShareViewPresenter, CreateShareViewPresenter>();
            _container.RegisterType<IDeleteShareView, DeleteShareView>();
            _container.RegisterType<IDeleteShareViewPresenter, DeleteShareViewPresenter>();
        }

        #endregion
    }
}